<!--
Date: 2025-08-13
Copyright (c) 2025 CAX Conversion Project
-->
<template>
  <div class="profile-library">
    <div class="mb-[10px]">
      <el-card shadow="hover">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true" size="small" label-width="80px">
          <el-form-item label="型材类型" prop="type">
            <el-select @change="typeChange" v-model="queryParams.type">
              <el-option v-for="item in profileTypes" :label="item.label" :value="item.value" :key="item.label"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="编号" prop="serialNumber" v-if="hasNum">
            <el-input v-model="queryParams.serialNumber" placeholder="请输入" clearable />
          </el-form-item>
          <el-form-item label="属性号" prop="attributeNumber" v-if="hasAttr">
            <el-input v-model="queryParams.attributeNumber" placeholder="请输入" clearable />
          </el-form-item>
          <el-form-item label="MAT1_ID" prop="mat1Id" v-if="hasMat">
            <el-input v-model="queryParams.mat1Id" placeholder="请输入" clearable />
          </el-form-item>
          <el-form-item style="padding-left: 80px">
            <el-button type="primary" icon="search" @click="doQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>

    <el-card shadow="hover">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @query-table="doQuery"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="profileList" ref="tableRef">
        <el-table-column
          :label="item.label"
          v-for="item in defaultColunms"
          :key="item.label"
          :fixed="item.fixed"
          :prop="item.prop"
          :width="item.width"
        />
        <el-table-column :label="item.label" v-for="item in resultColumns" :key="item.label" :prop="item.prop" />
        <el-table-column :label="item.label" v-for="item in cutColunms" :key="item.label" :fixed="item.fixed" :prop="item.prop" />
      </el-table>
      <div class="pagenation">
        <el-pagination
          v-show="total > 0"
          layout="prev, pager, next,jumper"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          :total="total"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>
<!-- 型材库 -->
<script name="profileResult" setup>
import {
  resultColumns,
  profileTypes,
  defaultColunms,
  columns1,
  columns2,
  columns3,
  columns4,
  columns5,
  columns6,
  columns7
} from '../profileLibrary.js';
import { getProfiletResultList } from '@/api/profileLibrary';

const loading = ref(false);
const tableRef = ref(null);
// 条件展示查询区域
const hasNum = ref(true);
const hasAttr = ref(true);
const hasMat = ref(true);
const cutColunms = ref(columns1);

const profileList = ref([]);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  type: 'ALL',
  serialNumber: '',
  attributeNumber: '',
  mat1Id: '',
  isAsc: 'descending'
});
const total = ref(0);
const showSearch = ref(true);

//查询数据
const doQuery = () => {
  getProfiletResultList(queryParams.value).then(async (res) => {
    if (res) {
      total.value = res.total;
      const result = await res?.rows?.map((el) => {
        return { ...el, ...el.isfdSectionResultDetailVo };
      });
      console.log(result);
      profileList.value = result;
    }
  });
};
// 翻页
const handleCurrentChange = (num) => {
  queryParams.value.pageNum = num;
  doQuery();
};

// 重置
const resetQuery = () => {
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    type: 'CAP',
    serialNumber: '',
    attributeNumber: '',
    mat1Id: '',
    isAsc: 'descending'
  };
  doQuery();
};
// 型材类型改变
const typeChange = (event) => {
  switch (event) {
    case 'CAP': {
      cutColunms.value = columns1;
      break;
    }
    case 'T': {
      cutColunms.value = columns2;
      break;
    }
    case 'I': {
      cutColunms.value = columns3;
      break;
    }
    case 'FI': {
      cutColunms.value = columns4;
      break;
    }
    case 'FZ': {
      cutColunms.value = columns5;
      break;
    }
    case 'FZFF': {
      cutColunms.value = columns5;
      break;
    }
    case 'FZAFF': {
      cutColunms.value = columns5;
      break;
    }
    case 'FC': {
      cutColunms.value = columns4;
      break;
    }
    case 'FCSF': {
      cutColunms.value = columns4;
      break;
    }
    case 'FL': {
      cutColunms.value = columns6;
      break;
    }
    case 'FLATI': {
      cutColunms.value = columns6;
      break;
    }
    case 'FLA': {
      cutColunms.value = columns6;
      break;
    }
    case 'FGO': {
      cutColunms.value = columns7;
      break;
    }
    case 'FGM': {
      cutColunms.value = columns7;
      break;
    }
    case 'FGI': {
      cutColunms.value = columns7;
      break;
    }
    case 'FGATIW': {
      cutColunms.value = columns7;
      break;
    }
    case 'FGTI': {
      cutColunms.value = columns7;
      break;
    }
    case 'FGA': {
      cutColunms.value = columns7;
      break;
    }
  }
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    type: event,
    serialNumber: '',
    attributeNumber: '',
    mat1Id: '',
    isAsc: 'descending'
  };
  doQuery();
};
onMounted(() => {
  doQuery();
});
</script>
<style lang="scss" scoped>
.profile-library {
  height: calc(100vh - 155px);
  overflow: auto;
  .tiltops {
    color: red;
  }
  .pagenation {
    display: flex;
    justify-content: end;
    margin-top: 10px;
  }
}
</style>